package com.work06.controller;

import com.work06.pojo.User;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;

/**
 * @author 绛河
 * @date 2023/6/1
 * @apiNote
 */
@Controller
public class UserController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @PostMapping("/register")
    public String register(User user, String verification) {
        System.out.println(user);

        if ("sms".equals(verification)){
            // 发送短信
            rabbitTemplate.convertAndSend("exchange", "sms", user);
            System.out.println("恭喜您,使用短信注册成功");
        } else if ("email".equals(verification)) {
            // 发送邮件
            rabbitTemplate.convertAndSend("exchange", "email", user);
            System.out.println("恭喜您,使用邮件注册成功");
        }

        return "success";
    }
}